﻿<sap:ActivityDesigner x:Class="Microsoft.Samples.SqlServer.Activities.Designers.SelectDataTableDesigner"
    xmlns:s="clr-namespace:System;assembly=mscorlib" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation" 
    xmlns:sql="clr-namespace:System.Data.SqlClient;assembly=System.Data" 
    xmlns:Model="clr-namespace:System.Activities.Presentation.Model;assembly=System.Activities.Presentation"  
    xmlns:local="clr-namespace:Microsoft.Samples.SqlServer.Activities" 
    xmlns:publisher="clr-namespace:Microsoft.Samples.SqlServer.Activities.ActivityPublishers" 
    Collapsible="True" Loaded="ActivityDesigner_Loaded">
    <sap:ActivityDesigner.Resources>
        <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        <sapc:ModelToObjectValueConverter x:Key="ModelToObjectValueConverter" />
 
        <DataTemplate x:Key="ShowAsCollapsed">
            <TextBlock Foreground="Gray">
                <TextBlock.Text>
                     <MultiBinding StringFormat="Select columns from {0}">
                        <Binding Path="ModelItem.TableSource" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="ShowAsExpanded">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                 <TextBlock Text="With connection" Grid.Row ="0" Grid.Column="1"
            HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5"/>
                <sapv:ExpressionTextBox HintText="SqlConnection" 
            Grid.Row ="0" Grid.Column="2" MaxWidth="150" MinWidth="150" Margin="5"
            OwnerActivity="{Binding Path=ModelItem}"
            Expression="{Binding Path=ModelItem.SqlConnectionBuilder, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
            ExpressionType="sql:SqlConnectionStringBuilder" />
                
                <TextBlock Padding="10,0,0,0" Text="From schema" Grid.Row ="1" Grid.Column="1"
            HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" />
                <ComboBox Margin="5" Grid.Row ="1" Grid.Column="2" Text="{Binding Path=ModelItem.Schema}" Name="schemaNameComboBox" 
                   IsEditable="True" IsReadOnly="True" MaxDropDownHeight="200" DropDownOpened="schemaNameComboBox_DropDownOpened" DropDownClosed="schemaNameComboBox_DropDownClosed" />


                <TextBlock Padding="10,0,0,0" Text="and table" Grid.Row ="2" Grid.Column="1"
            HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5"/>                

                <ComboBox Margin="5" Grid.Row ="2" Grid.Column="2" Text="{Binding Path=ModelItem.TableSource}" Name="tableNameComboBox" 
                   IsEditable="True" IsReadOnly="True" MaxDropDownHeight="200" DropDownOpened="tableNameComboBox_DropDownOpened" DropDownClosed="tableNameComboBox_DropDownClosed" />

                <TextBlock Padding="10,0,0,0" Text="Select columns" Grid.Row ="3" Grid.Column="1"
            HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5"/>

                <ComboBox Margin="5" Grid.Row ="3" Grid.Column="2" Text="Select column names" Name="columnNamesComboBox" 
                   IsEditable="True" IsReadOnly="True" MaxDropDownHeight="200" DropDownOpened="columnNamesComboBox_DropDownOpened" DropDownClosed="columnNamesComboBox_DropDownClosed" />


                <sap:WorkflowItemsPresenter
                Grid.Row ="4" Grid.Column="0" Grid.ColumnSpan="3"                                        
                Margin="5" MinHeight="30" AllowedItemType="{x:Type TypeName=local:SqlWhere}" 
                Items="{Binding Path=ModelItem.WhereActivities}">
                    <sap:WorkflowItemsPresenter.SpacerTemplate>
                        <DataTemplate>
                            <TextBlock Background="GhostWhite" Width="200" HorizontalAlignment="Center" TextAlignment="Center" FontStyle="Italic">Where columns are ...</TextBlock>
                        </DataTemplate>
                    </sap:WorkflowItemsPresenter.SpacerTemplate>

                    <sap:WorkflowItemsPresenter.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </sap:WorkflowItemsPresenter.ItemsPanel>
                </sap:WorkflowItemsPresenter>



                <sap:WorkflowItemPresenter HintText="ContentPart"
                    Grid.Row ="5" Grid.Column="0" Grid.ColumnSpan="3"                                      
                Margin="0" MinHeight="30" AllowedItemType="{x:Type TypeName=publisher:DocumentPart}" 
                Item="{Binding Path=ModelItem.DocumentPartActivity, Mode=TwoWay}"/>

            </Grid>
        </DataTemplate>

        <Style x:Key="StyleWithCollapse" TargetType="{x:Type ContentPresenter}">
            <Setter Property="ContentTemplate" 
                Value="{DynamicResource ShowAsExpanded}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="False">
                    <Setter Property="ContentTemplate" 
                        Value="{DynamicResource ShowAsCollapsed }"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>

    <sap:ActivityDesigner.Icon>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <ImageDrawing>
                    <ImageDrawing.Rect>
                        <Rect Location="0,0"  Size="16,16" />
                    </ImageDrawing.Rect>
                    <ImageDrawing.ImageSource>
                        <BitmapImage UriSource="SelectDataTableActivity.png"/>
                    </ImageDrawing.ImageSource>
                </ImageDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </sap:ActivityDesigner.Icon>

    <Grid>
        <ContentPresenter Style="{DynamicResource StyleWithCollapse}" 
            Content="{Binding}" />
    </Grid>
</sap:ActivityDesigner>

